<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div class="bjui-pageHeader">
    <form id="pagerForm" data-toggle="ajaxsearch" action="table.html" method="post">
        <ul class="bjui-searchBar">
            <li><label>角色名称：</label><input type="text" id="customNo" value="" name="code" class="form-control" size="10" /></li>
            <li><button type="submit" class="btn-default" data-icon="search">查询</button></li>
            <li><a class="btn btn-orange" href="javascript:;" data-toggle="reloadsearch" data-clear-query="true" data-icon="undo">清空查询</a></li>
        </ul>
    </form>
</div>
<div class="bjui-pageContent">
    <div class="bjui-headBar">
        <ul>
        <li class="left"><a href="/admin/add_role" class="btn btn-default" data-toggle="dialog" data-width="500" data-height="300" data-id="dialog-mask" data-mask="true">新增角色</a></li>
            <li class="left"><button type="button" class="btn-blue">修改角色</button></li>
            <li class="left"><button type="button" class="btn-red">删除角色</button></li>
        </ul>
    </div>
    <table class="table table-bordered table-hover table-striped table-top" data-layout-h="0">
        <thead>
            <tr>
                <th data-order-field="name">角色名称</th>
                <th data-order-direction="asc" data-order-field="created">创建时间</th>
                <th width="200">操作</th>
            </tr>
        </thead>
        <tbody id="result">
        </tbody>
        
        <p style="display:none">
			<textarea id="templateContainer" rows="0" cols="0">
	        	{#foreach $T as data}
					<tr>
		                <td>{$T.data.name}</td>
		                <td>{$T.data.created}</td>
		                <td>
		                    <a href="form.html?id=1" class="btn btn-red" data-toggle="navtab" data-reload-warn="本页已有打开的内容，确定将刷新本页内容，是否继续？" data-title="编辑-孙悟空">编辑角色</a>
		                	<a href="form.html?id=1" class="btn btn-green" data-toggle="navtab" data-reload-warn="本页已有打开的内容，确定将刷新本页内容，是否继续？" data-title="编辑-孙悟空">分配权限</a>
		                </td>
		            </tr>
				{#/for}
			</textarea>
		</p>
    </table>
    <div class="bjui-footBar">
        <div class="pages">
            <span>每页&nbsp;</span>
            <div class="selectPagesize">
                <select data-toggle="selectpicker" data-togglechange="do">
                    <option value="30">30</option>
                    <option value="60">60</option>
                    <option value="120">120</option>
                    <option value="150">150</option>
                </select>
            </div>
            <span>&nbsp;条，共 600 条</span>
        </div>
        <div class="pagination-box" data-toggle="pagination" data-total="600" data-page-size="30" data-page-current="2">
        </div>
    </div>
</div>

<script type="text/javascript">
(function($){
	//创建包名
	CH.package("com.ch.controller");
	CH.package("com.ch.model");
	CH.package("com.ch.view");
	
	//创建模型层类
	com.ch.model.RoleModel = CH.create({
		construct : function() {
			this.value = null;
		},
		
		loadData : function(result) {
			this.values = result.data;
			for(var i = 0; i < this.values.length; i++) {
				var value = this.values[i];
				value.created = CH.utils.toLocalTime(value.created);
			}
		}
	});
	
	//创建视图层类
	com.ch.view.RoleView = CH.create({
		construct : function( controller ) {
			this.controller = controller;
		},
		
		render : function(model) {
			CH.template('#result', 'templateContainer', model.values);
		}
	});
	
	//创建控制器类
	com.ch.controller.RoleController = CH.create({
		construct : function() {
			this.view = new com.ch.view.RoleView(this);
			this.model = new com.ch.model.RoleModel();
		},
		
		get : function(page, limit) {
			var url = '/webapi/role/'+page + '/' + limit;
			CH.GetRequest(url, this.getSuccess, this);
		},
		
		getSuccess : function(result) {
			this.model.loadData(result);
			this.view.render(this.model);
		},
		
		submitForm : function() {
			var url = './api/storeConfig/s';
			var data = JSON.stringify(this.view.getValues());
			var contentType = "application/json";
			
			CH.PostRequest(url, data, contentType, this.submitSuccess, this);
		},
		
		submitSuccess : function(result) {
			if(result.code == SUCCESS) {
				CH.utils.showMessageOK("保存成功!");
			}
			else if(result.code == SERVER_ERROR) {
				CH.utils.showMessageOK("服务器错误!");
			}
		}
	});
	
	$(document).ready(function() {
		var controller = new com.ch.controller.RoleController();
		controller.get(0, 10);
	});
	
})(jQuery);
</script>



